package udes.assassin.structure;

import com.google.android.maps.GeoPoint;

import udes.assassin.server.api.DataStructure.InGameUserStructure;
import udes.assassin.server.api.DataStructure.UserStructure;
import android.text.format.Time;

public class Player implements Comparable<Player>{
	private String mName;
	private String mId;
	private GeoPoint mGeoPoint;
	private int mScore;
	private String mTarget;
	private Time mDeathTime;
	private boolean mIsReady;
	private boolean mIsAlive;
	
	public Player(UserStructure aUser){
		mId = aUser.playerName.trim();
		mName = aUser.realName.trim();
		mIsReady = aUser.ready;
		mIsAlive = true;
	}
	
	public Player(InGameUserStructure aInGameUser){
		mName = aInGameUser.realName;
		mId = aInGameUser.playerName;
		mGeoPoint = new GeoPoint(aInGameUser.latitude, aInGameUser.longitude);
		mScore = aInGameUser.score;
		mTarget = aInGameUser.target; // Get NAME with Id
		// see how to convert this TODO
		//mDeathTime = new Time(aInGameUser.deathTime);
		//mIsReady = aInGameUser.ready;
		mIsAlive = aInGameUser.deathTime == -1;
	}
	
	public String getName(){
		return mName;
	}
	
	public String getId(){
		return mId;
	}
	
	public GeoPoint getGeoPoint(){
		return mGeoPoint;
	}
	
	public float getLatitude(){
		return (float) (mGeoPoint.getLatitudeE6() * Math.pow(10.0f, -6.0f));
	}
	
	public float getLongitude(){
		return (float) (mGeoPoint.getLongitudeE6() * Math.pow(10.0f, -6.0f));
	}
	
	public int getScore(){
		return mScore;
	}
	
	public String getTargetName(){
		return mTarget;
	}
	
	public Time getDeathTime(){
		return mDeathTime;
	}
	
	public boolean isReady(){
		return mIsReady;
	}

	public boolean isAlive() {
		return mIsAlive;
	}

	public int compareTo(Player arg0) {
		if(mScore>arg0.mScore)
            return -1;
        else if(mScore<arg0.mScore)
            return +1;
        else
            return 0;
	}
}
